import request from '@/utils/request'

const api = {
  login: '/login',
  getUserInfo: '/users/',
  getUsers: '/users',
  postUser: '/users',
  deleteUser: '/users/',
  putUser: '/users/',
  putUserState: '/users/',
  putUserRole: '/users/'
}

export function login(data) {
  return request({
    url: api.login,
    method: 'post',
    data
  })
}

export function getUserInfo(id) {
  return request({
    url: `${api.getUserInfo}${id}`,
    method: 'get',
    cache: true
  })
}

export function getUsers(params) {
  return request({
    url: api.getUsers,
    method: 'get',
    params,
    cache: true
  })
}

export function postUser(data) {
  return request({
    url: api.postUser,
    method: 'post',
    data
  })
}

export function deleteUser(id) {
  return request({
    url: `${api.deleteUser}${id}`,
    method: 'delete'
  })
}

export function putUser(data) {
  return request({
    url: `${api.putUser}${data.id}`,
    method: 'put',
    data
  })
}

export function putUserState(data) {
  return request({
    url: `${api.putUserState}${data.id}/state/${!data.mg_state}`,
    method: 'put'
  })
}

export function putUserRole(data) {
  return request({
    url: `${api.putUserRole}${data.id}/role`,
    method: 'put',
    data
  })
}

